import copy

lst = []    # 存储状态
times = 1   # 移动步数


def solution(n) -> '输入n个圆盘数量':
    a = '1'
    b = '2'
    c = '3'
    global lst
    lst = [1 for _ in range(n)]
    oldList = copy.deepcopy(lst)
    helper(a, b, c, n)
    print('第', 1, '层:(', oldList, '->', lst, ')')


def helper(a, b, c, n):
    global lst
    global times
    length = len(lst)
    if n == 1:
        print('\033[31m [', times, ']\t', 'Move', chr(n + ord('A') - 1), 'from', a, '->', c, '\033[0m')
        lst[length - n] = eval(c)
        times += 1
    elif n > 1:
        oldList = copy.deepcopy(lst)
        helper(a, c, b, n - 1)
        print('第', length - n + 2, '层:(', oldList, '->', lst, ')')

        oldList = copy.deepcopy(lst)
        print('\033[31m [', times, ']\t', 'Move', chr(n + ord('A') - 1), 'from', a, '->', c, '\033[0m')
        times += 1
        lst[length - n] = eval(c)
        print('第', length - n + 2, '层:(', oldList, '->', lst, ')')

        oldList = copy.deepcopy(lst)
        helper(b, a, c, n - 1)
        print('第', length - n + 2, '层:(', oldList, '->', lst, ')')
        print("================回溯上一层===============================")


solution(eval(input('盘子数量')))
